package com.sx.pipeline.ui.examine.record

import android.view.View
import androidx.viewpager2.widget.ViewPager2
import com.alibaba.android.arouter.facade.annotation.Route
import com.google.android.material.tabs.TabLayoutMediator
import com.sx.pipeline.BR
import com.sx.pipeline.R
import com.sx.pipeline.app.base.CYDataBindingBaseActivity
import com.sx.pipeline.arouth.RoutePath.Mine.OPERATOR_EXAMINE_RECORD
import com.sx.pipeline.databinding.ActExamineManagerBinding

@Route(path = OPERATOR_EXAMINE_RECORD)
class ExamineRecordAct : CYDataBindingBaseActivity<ActExamineManagerBinding, ExamineRecordVM>(
    R.layout.act_examine_manager
), View.OnClickListener {

    private lateinit var examinePageAdapter: ExamineRecordPageAdapter

    override fun initData() {
        mBinding.setVariable(BR.onClick, this)
        mBinding.titleBar.leftView.setOnClickListener {
            finish()
        }
        initPager()
    }

    /**
     * 初始化ViewPager
     */
    private fun initPager() {
        if (mBinding.viewPager.adapter == null) {
            examinePageAdapter = ExamineRecordPageAdapter(
                mViewModel.getExamineTabsList(),
                mViewModel.getExamineTaskTabsIdList(),
                supportFragmentManager,
                lifecycle
            )
        }
        mBinding.viewPager.adapter = examinePageAdapter
        mBinding.viewPager.offscreenPageLimit = mViewModel.getExamineTabsList().size
        mBinding.viewPager.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
            override fun onPageSelected(position: Int) {

            }
        })

        //绑定tabLayout和viewPager
        TabLayoutMediator(
            mBinding.tab, mBinding.viewPager,
            true, true
        ) { tab, position ->
            tab.text = mViewModel.getExamineTabsList()[position]
        }.attach()
    }

    override fun onClick(v: View?) {
        when (v?.id) {

        }
    }


    override fun onDestroy() {
        super.onDestroy()
    }

}